package txt2bib;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;


import java_cup.runtime.Symbol;
import java_cup.runtime.lr_parser;

import java.lang.reflect.Field;


public class ProvaParserIEEE {
	lr_parser parser = null;
	ScannerIEEE scanner = null;
	boolean do_debug_parse = false;
	
	public ProvaParserIEEE() {
		
		
	}
	
	private void createScanner(File file) throws FileNotFoundException {
		FileReader reader = new FileReader(file);
		scanner = new ScannerIEEE(reader);
	}
	
	private void createParser(ScannerIEEE scanner) throws Exception {
		if (scanner != null)
			parser = new GrammarIEEECup(scanner);
		else
			throw new Exception("Scanner is null");
	}
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 /* open input files, etc. here */
	  ProvaParserIEEE pp = new ProvaParserIEEE();
	  
      Symbol parse_tree = null;
		try {
			pp.createScanner(new File("IEEEfile.txt"));	
			
			Symbol symbol = pp.scanner.next_token();
			while (symbol.sym != 0 )
			{
				System.out.println(symbol + " Riconosciuto : " + symbol.value);
				
				symbol = pp.scanner.next_token();
				
			}
			
			
//			Object result = pp.parser.parse().value;
//		    System.out.println(result.toString());
			pp.createScanner(new File("IEEEfile.txt"));	
			pp.createParser(pp.scanner);

			try {
		        if (pp.do_debug_parse)
		          parse_tree = pp.parser.debug_parse();
		        else
		          parse_tree = pp.parser.parse();
		        
		        
		      } catch (Exception e) {
		        /* do cleanup here - - possibly rethrow e */
		      } finally {
			/* do close out here */
		      }
			
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
